import {
  checkSelect,
  checkTitleLenth,
} from "@/portal-common/utils/testedFunc/formValidate/index.js";
import { skuPage } from "@/portal-common/commonPage/template/detailAndAddCard/addEditDetail/functions/mock.js";
export function dataArrBase(v) {
  return [
    {
      prop: "projectName",
      label: "项目名称",
      rules: [
        {
          required: true,
          validator: checkTitleLenth({ max: 50 }),
          trigger: "change",
        },
      ],
      type: "input",
    },
    {
      prop: "urgentLevel",
      label: "紧急程度",
      rules: [
        {
          required: true,
          validator: checkSelect(),
          trigger: "change",
        },
      ],
      type: "select",
      props: {
        label: "name",
        value: "id",
      },
      options: v.selectData.urgentLevelArr,
      isHidden: v.modeType == "detail",
      change(val, arr) {
        v.ruleForm.urgentLevelName = arr[0].name;
      },
    },
    {
      prop: "urgentLevelName",
      label: "紧急程度",
      type: "text",
      isHidden: v.modeType != "detail",
    },
    {
      prop: "date",
      label: "实施日期",
      type: "daterange",
    },
    {
      prop: "refitMode",
      label: "加装方式",
      rules: [
        {
          required: true,
          validator: checkSelect(),
          trigger: "change",
        },
      ],
      type: "select",
      props: {
        label: "name",
        value: "id",
      },
      options: v.selectData.refitModeArr,
      isHidden: v.modeType == "detail",
    },
    {
      prop: "refitModeName",
      label: "加装方式",
      type: "text",
      isHidden: v.modeType != "detail",
    },
    {
      prop: "status",
      label: "状态",
      rules: [
        {
          required: true,
          validator: checkSelect(),
          trigger: "change",
        },
      ],
      type: "radio",
      props: {
        label: "name",
        value: "id",
      },
      options: v.selectData.statusArr,
      isHidden: v.modeType == "detail",
    },
    {
      prop: "statusName",
      label: "状态",
      type: "text",
      isHidden: v.modeType != "detail",
    },
    {
      prop: "remark",
      label: "备注",
      rules: [
        {
          required: false,
          validator: checkTitleLenth({ required: false, max: 200 }),
          trigger: "change",
        },
      ],
      type: "textarea",
    },
  ];
}
export function dataArrfile(v) {
  return [
    {
      label: "附件",
      prop: "refitFiles",
      type: "dstUpload",
      listType: "text",
      filterOpts: { type: "", size: 10 },
      limit: 100,
      rules: [
        {
          required: true,
          validator: checkSelect(),
          trigger: "change",
        },
      ],
      showTip: true,
    },
  ];
}
export function dataArrDialog(v) {
  return [
    {
      label: "加装类型",
      prop: "refitType",
      type: "select",
      class: "dst-block",
      rules: [
        {
          required: true,
          validator: checkSelect(),
          trigger: "change",
        },
      ],
      props: {
        label: "name",
        value: "id",
      },
      options: v.selectData.refitTypeArr,
      change(val, item) {
        console.log(item, 98989);
        v.ruleFormDialog.refitTypeName = item[0].name;
      },
    },
    {
      label: "加装项SKU",
      prop: "refitSkuCode",
      type: "select",
      class: "dst-block",
      props: {
        label: "name",
        value: "code",
        rightLabel: "code",
      },
      rules: [
        {
          required: true,
          validator: checkSelect(),
          trigger: "change",
        },
      ],
      remote: true,
      remoteMethod(codeAndName) {
        skuPage({
          pageSize: 10,
          codeAndName: codeAndName,
          types: [v.ruleFormDialog.refitType],
        }).then((res) => {
          const arr = [];
          res.data.list.forEach((item) => {
            if (item.code) {
              arr.push(item);
            }
          });
          v.selectData.refitSkuArr = arr;
        });
      },
      options: v.selectData.refitSkuArr,
      change(val, item) {
        v.ruleFormDialog.refitSkuName = item[0].name;
      },
    },
  ];
}
